﻿using M.Warehouse.API.Application.Command.PickingCommand;
using M.Warehouse.Domain.DTO;
using M_ApiResult;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace M.Warehouse.API.Controllers
{
    /// <summary>
    /// 生产领料控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PickingController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PickingController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 创建生产领料
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreatePicking(PickingCreateCommand command)
        {
            ApiResult<int> result= new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 生产领料显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<PickingShowDTO>>> HandlePicking([FromQuery] PickingShowCommand command)
        {
            ApiResult<List<PickingShowDTO>> result = new ApiResult<List<PickingShowDTO>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
